package com.example.demo.repository;

import com.example.demo.domain.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 菜单管理Repository
 *
 * @Author zmf
 * @Date 2018/12/12  17:35
 */
@Repository
public interface MenuRepository extends JpaRepository<Menu,Long> {
    @Modifying
    @Query(value = "UPDATE CS_SM_MENU_D SET FULL_MENU_ID = :fullMenuId WHERE CS_SM_MENU_ID = :id",nativeQuery =true)
    void updateFullMenuId(@Param(value = "fullMenuId") String fullMenuId, @Param(value = "id") Long id);

    @Modifying
    @Query(value = "UPDATE CS_SM_MENU_D SET FULL_MENU_ID = :fullMenuId,PARENT_ID =:pid WHERE CS_SM_MENU_ID = :id",nativeQuery =true)
    void updateFullMenuIds(@Param(value = "fullMenuId") String fullMenuId,
                           @Param(value = "pid") String pid,
                           @Param(value = "id") Long id);

    @Modifying
    @Query(value = "UPDATE CS_SM_MENU_D SET ENABLED = 0 WHERE FULL_MENU_ID LIKE :menuId",nativeQuery =true)
    void DisabledChildren(@Param(value = "menuId") String menuId);

}
